//
//  BaseTabBarController.m
//  MainDemo
//
//  Created by FM on 2017/1/7.
//  Copyright © 2017年 FM. All rights reserved.
//

#import "BaseTabBarController.h"
#import "BaseNavigationController.h"
#import "FirstViewController.h"
#import "ThreeViewController.h"
#import "FourViewController.h"
#import "FiveViewController.h"
#import "BaseTabBar.h"
#import "Define.h"
@interface BaseTabBarController ()

@end

@implementation BaseTabBarController
+ (void)initialize
{
    // 通过appearance统一设置所有UITabBarItem的文字属性
    // 后面带有UI_APPEARANCE_SELECTOR的方法, 都可以通过appearance对象来统一设置
    NSMutableDictionary *attrs = [NSMutableDictionary dictionary];
    attrs[NSFontAttributeName] = [UIFont systemFontOfSize:12];
    attrs[NSForegroundColorAttributeName] = UIColorFromRGB(0x2a2a2a);
    
    NSMutableDictionary *selectedAttrs = [NSMutableDictionary dictionary];
    selectedAttrs[NSFontAttributeName] = attrs[NSFontAttributeName];
    selectedAttrs[NSForegroundColorAttributeName] =RGBCOLOR(230, 6, 90);
//    selectedAttrs[NSForegroundColorAttributeName]=UIColorFromRGB(0x2a2a2a);
    
    UITabBarItem *item = [UITabBarItem appearance];
    [item setTitleTextAttributes:attrs forState:UIControlStateNormal];
    [item setTitleTextAttributes:selectedAttrs forState:UIControlStateSelected];
//    //设置标题栏内容颜色
    [[UITabBar appearance] setTintColor:RGBCOLOR(230, 6, 90)];
    //设置TabBar背景颜色
    [[UITabBar appearance] setBackgroundColor:[UIColor whiteColor]];
    
    
    
    //设置导航栏颜色
     [[UINavigationBar appearance] setBarTintColor:[UIColor whiteColor]];
    
    //设置内容颜色
      [[UINavigationBar appearance] setTintColor:[UIColor colorWithRed:0.2 green:0.2 blue:0.2 alpha:1.0]];
    
    //设置字体属性
      [[UINavigationBar appearance] setTitleTextAttributes:@{NSFontAttributeName : [UIFont systemFontOfSize:18],
                                                            NSForegroundColorAttributeName:[UIColor colorWithRed:0.2 green:0.2 blue:0.2 alpha:1.0]}];
    
}
- (void)viewDidLoad {
    [super viewDidLoad];
    // Do any additional setup after loading the view.
    self.view.backgroundColor=[UIColor whiteColor];
//    [self.navigation lt_];
    // 添加子控制器
    
    [self setupChildVc:[[FirstViewController alloc] init] title:@"首页" image:@"主页未选中" selectedImage:@"主页选择"];
    
    [self setupChildVc:[[FourViewController alloc] init] title:@"楼盘方案" image:@"效果图未选择" selectedImage:@"效果图选中"];
    
    [self setupChildVc:[[ThreeViewController alloc] init] title:@"社交圈" image:@"社交圈未选择" selectedImage:@"社交圈选中"];

    
//    [self setupChildVc:[[FourViewController alloc] init] title:@"效果图" image:@"tabBar_essence_icon" selectedImage:@"tabBar_essence_click_icon"];
    [self setupChildVc:[[FourViewController alloc] init] title:@"我的" image:@"我的未选择" selectedImage:@"我的选中"];
    
//    [self setupChildVc:[[FirstViewController alloc] init ] title:<#(NSString *)#> image:<#(NSString *)#> selectedImage:<#(NSString *)#>];
    // 更换tabBar
    [self setValue:[[UITabBar alloc] init] forKeyPath:@"tabBar"];
    
}
/**
 * 初始化子控制器
 */
- (void)setupChildVc:(UIViewController *)vc title:(NSString *)title image:(NSString *)image selectedImage:(NSString *)selectedImage
{
    // 设置文字和图片
    vc.navigationItem.title = title;
//    vc.navigationItem
    vc.tabBarItem.title = title;
    vc.tabBarItem.image = [UIImage imageNamed:image];
    vc.tabBarItem.selectedImage = [UIImage imageNamed:selectedImage];
    
    // 包装一个导航控制器, 添加导航控制器为tabbarcontroller的子控制器
    BaseNavigationController *nav = [[BaseNavigationController alloc] initWithRootViewController:vc];
    [self addChildViewController:nav];
}
- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

/*
#pragma mark - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    // Get the new view controller using [segue destinationViewController].
    // Pass the selected object to the new view controller.
}
*/

@end
